package com.dongline.test.gongtonghaoyou;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class Friend2Driver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        Configuration configuration = new Configuration();


        Job job=Job.getInstance(configuration);

        ///这句话很重要必须加上
        job.setJarByClass(Friend2Driver.class);

        job.setMapperClass(Friend2Mapper.class);
        job.setReducerClass(Friend2Reducer.class);


        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(Text.class);



        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);

        //如果存在这个输出路径就删除这个输出路径
        FileSystem fileSystem=new Path("/").getFileSystem(configuration);
        if(fileSystem.exists(new Path("D:/firends/output1")))
        {
            fileSystem.delete(new Path("D:/friends/output1"),true);
        }

        FileInputFormat.setInputPaths(job,new Path("D:/friends/output"));
        FileOutputFormat.setOutputPath(job,new Path("D:/friends/output1"));

        boolean re= job.waitForCompletion(true);

        System.exit(re?0:1);
    }
}
